<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" layout:decorate="main"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head>
    <title>用户添加</title>
    <link th:href="@{../localcss/crmlist.css}" href="../../static/localcss/crmadd.css" rel="stylesheet">
    <link th:href="@{../css/treetable/bootstrap-treeview.min.css}" href="../../static/css/treetable/bootstrap-treeview.min.css" rel="stylesheet">
    <style>
        .treeview ul li{
            display: block!important;
            width: 100%!important;
        }
        .treeview .list-group{
            width: 100% !important;
        }
        
    </style>
</head>
<body>
<div layout:fragment="content">
    <div class="">
        <div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>新增资源信息 <i class="fa fa-user"></i></h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <div class="clearfix"></div>
                        <form class="form-horizontal form-label-left" th:action="@{/right/save}" action="/right/save" method="post">
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="rightParentCodeText"> 上级 <span class="required">*</span>
                                </label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <input id="rightParentCodeText" class="form-control col-md-7 col-xs-12"
                                           data-validate-length-range="10" data-validate-words="1" name="rightParentCodeText" required="required"
                                           placeholder="请选择" type="text" onclick="selectTree()">
                                    <input name="rightParentCode" id="rightParentCode" type="hidden">
                                    <ul id="parentList" style="display: flex;width: 105%!important; margin-left: -3.9rem!important;">
                                    
                                    </ul>
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="rightCode"> 资源编号 <span class="required">*</span>
                                </label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <input id="rightCode" class="form-control col-md-7 col-xs-12"
                                           data-validate-length-range="10" data-validate-words="1" name="rightCode" required="required"
                                           placeholder="请输入资源编号" type="text" readonly>
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="rightText"> 资源名称 <span class="required">*</span>
                                </label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <input id="rightText" class="form-control col-md-7 col-xs-12"
                                           data-validate-length-range="10" data-validate-words="1" name="rightText" required="required"
                                           placeholder="请输入资源名称" type="text">
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12"  for="rightType"> 资源类型 <span class="required">*</span></label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <select name="rightType" id="rightType" class="form-control" required="required">
                                        <option th:each="temp:${rightTypes}" th:value="${temp.dictValue}" th:text="${temp.dictItem}" value="">菜单类型</option>
                                    </select>
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="rightTip"> 资源简称 <span class="required">*</span>
                                </label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <input id="rightTip" class="form-control col-md-7 col-xs-12"
                                           data-validate-length-range="10" data-validate-words="1" name="rightTip" required="required"
                                           placeholder="请输入资源简称" type="text">
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="rightUrl"> 资源路径  </label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <input id="rightUrl" class="form-control col-md-7 col-xs-12" data-validate-length-range="10"
                                           data-validate-words="1" name="rightUrl" placeholder="请输入资源路径" type="text">
                                </div>
                            </div>
                    
    
                            <div class="form-group">
                                <div class="col-md-6 col-md-offset-3">
                                    <button id="send" type="submit" class="btn btn-success">保存</button>
                                    <button type="button" class="btn btn-primary" id="back">返回</button>
                                    <br/><br/>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
  
</div>
</body>
<script layout:fragment="js" th:inline="javascript">
    $(document).ready(function(){
        $("#back").on("click",function(){
            window.history.back();
        });
    });
    
    function selectTree(){
       
        var defaultData=[[${parentList}]];
        $("#parentList").treeview({
            data:defaultData,
            levels:1,
            onNodeSelected: function (event,node) {
                $("#rightParentCode").val(node.id);
                var rightCodeText=node.id;
                if(node.nodes){
                    rightCodeText+="0"+(node.nodes.length+1)
                }else{
                    rightCodeText+="01"
                }
                $("#rightCode").val(rightCodeText);
                $("#rightParentCodeText").val(node.text);
                $("#parentList").hide()
                // console.log(node)
            }
        })
        $("#parentList").show()
    }
    
</script>
</html>